//
//  CGNotice.m
//  SchoolClient
//
//  Created by mac on 15/11/5.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CGNotice.h"

@implementation CGNotice

-(id)initWithTitle:(NSString *)title
           andTime:(NSString *)time
        andContent:(NSString *)content
           andDate:(NSDate *)date
     andCompany_id:(NSString *)company
      andSchool_id:(NSString *)school{
    if (self = [super init]) {
        self.title = title;
        self.time = time;
        self.content = content;
        self.date = date;
        self.company_id = company;
        self.school_id = school;
    }
    return self;
}


-(void)encodeWithCoder:(NSCoder *)aCoder{

    [aCoder encodeObject:self.title forKey:@"title"];
    [aCoder encodeObject:self.time forKey:@"time"];
    [aCoder encodeObject:self.content forKey:@"content"];
    [aCoder encodeObject:self.date forKey:@"date"];
    [aCoder encodeObject:self.company_id forKey:@"company"];
    [aCoder encodeObject:self.school_id forKey:@"school"];

}

-(id)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super init]) {
        self.title = [aDecoder decodeObjectForKey:@"title"];
        self.time = [aDecoder decodeObjectForKey:@"time"];
        self.content = [aDecoder decodeObjectForKey:@"content"];
        self.date = [aDecoder decodeObjectForKey:@"date"];
        self.company_id = [aDecoder decodeObjectForKey:@"company"];
        self.school_id = [aDecoder decodeObjectForKey:@"school"];
    }
    return self;
}

/*
 日期之间比较可用以下方法
 - (BOOL)isEqualToDate:(NSDate *)otherDate;
 与otherDate比较，相同返回YES
 
 - (NSDate *)earlierDate:(NSDate *)anotherDate;
 与anotherDate比较，返回较早的那个日期
 
 - (NSDate *)laterDate:(NSDate *)anotherDate;
 与anotherDate比较，返回较晚的那个日期
 */

- (NSComparisonResult)dateCompare:(CGNotice *)otherNotice{
    NSDate *date1 = self.date;
    NSDate *date2 = otherNotice.date;
    if ([date1 isEqualToDate:date2]) {
        return NSOrderedSame;
    }else if ([date1 earlierDate:date2]) {
        return NSOrderedAscending;
    }else{
        return NSOrderedDescending;
    }
}



@end
